/*
 * $Id: CustomerFeed.java 12 2011-12-08 14:20:30Z kuengcurs@gmail.com $
 * --------------------------------------------------------------------------------------
 * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 *
 * The software in this package is published under the terms of the CPAL v1.0
 * license, a copy of which has been included with this distribution in the
 * LICENSE.txt file.
 */

package org.mule.integration.module;

import org.mule.api.MuleEventContext;
import org.mule.api.lifecycle.Callable;
import org.mule.api.lifecycle.Initialisable;
import org.mule.api.lifecycle.InitialisationException;
import org.mule.transport.NullPayload;
import org.mule.util.IOUtils;

import java.io.IOException;
import java.io.InputStream;
import java.text.MessageFormat;
import java.util.Iterator;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class CustomerFeed implements Initialisable, Callable
{
    
    private Iterator<Customer> lines;
    
    protected transient Log logger = LogFactory.getLog(getClass());
    
    public void initialise() throws InitialisationException
    {
        lines = CustomerRegistry.getCustomers().iterator();
    }

    public Object onCall(MuleEventContext eventContext) throws Exception
    {
        if (lines.hasNext())
        {
            Customer cus = lines.next();
            return cus;
        }
        else
        {
            return NullPayload.getInstance();
        }
    }
}


